#ifndef XKIT_COLLECTIONS_H
#define XKIT_COLLECTIONS_H

#include "losu.h"
#include "platform/platform.h"

#include "../ref.h"
#include "../xkit.h"

static inline void *getCPointer(losu_vm_t vm, losu_object_t unit) {
    const losu_object_t o = obj_unitindexstr(vm, *unit, "__cptr__");
    if (o && o->type == losu_object_type_pointer) {
        return (obj_getptr(vm, o));
    } else {
        __error_UnavailableObject(vm);
        return NULL;
    }
}

static inline void setCPointer(losu_vm_t vm, losu_object_t unit, void *p) {
    if (obj_unitsetstr(vm, *unit, "__cptr__", obj_newptr(vm, p)) == 1) {
        __error_UnavailableObject(vm);
    }
}

#endif
